clear
close all
clc

fntsize=14;
w=500;
h=w*2/(1+sqrt(5));
col=[0;0.5;0.8;1]*ones(1,3);
se=1.96;
printyes=1;

x_ASM=(-4:1:5)';
x_CMF=(0:1:1)';

%% Load annual estimates (ASM), save variable names and plot annual VShape
[data,labels]=xlsread('DataForFigures.xlsx','VShape_ann','B1:U6');
[M,N]=size(labels);
dLS_unw_est = data(1,1:10)';
dLS_unw_se  = data(2,1:10)';
dLS_VAw_est = data(1,11:20)';
dLS_VAw_se  = data(2,11:20)';

% Plot Fig. IX(b): VShape of LL establishments in ASM (annual frequency)
figure('position',[0 0 w h]);
hold on
a=bar([x_ASM x_ASM],[dLS_VAw_est dLS_unw_est],1);
errorbar([x_ASM-0.14 x_ASM+0.14],[dLS_VAw_est dLS_unw_est],se*[dLS_VAw_se dLS_unw_se],'.','linewidth',1,'color','k','marker','o','markerfacecolor','k')
a(1).FaceColor = col(2,:);
a(2).FaceColor = col(3,:);
ax = gca;ax.YGrid = 'on';
set(gca,'ylim',[-0.32 0.0],'ytick',(-0.3:0.05:0.0),'xlim',[min(x_ASM)-0.5 max(x_ASM)+0.5],'xtick',x_ASM,'xticklabel',{'$t-4$';'';'$t-2$';'';'$t$';'';'$t+2$';'';'$t+4$';''},'fontsize',fntsize)
set(gca,'ticklabelinterpreter','latex')
xlabel('Cumulative change from $t-5$ to ...','interpreter','latex','fontsize',fntsize)
title('$\Delta\lambda_t^{LL}-\Delta\lambda_t^{Non-LL}$: ASM','fontsize',fntsize,'interpreter','latex');
lgnd=legend(a,{'VA-weighted';'Unweighted'},'fontsize',fntsize,'location','se','interpreter','latex');
set(lgnd,'color','white');
if printyes==1
    print('../Figures/Fig_VShape_LSann_cum.eps','-depsc')
end


%% Load quinquennial estimates (Census) and save variable names
% clear
clc

[data,labels]=xlsread('DataForFigures.xlsx','VShape','B1:Q15');
[M,N]=size(labels);

    assignin('base',strcat(labels{1,1},'_unw_est'),data(1,1:2)');
    assignin('base',strcat(labels{1,1},'_unw_se') ,data(2,1:2)');

    assignin('base',strcat(labels{1,1},'_unw_1970s_est'),data(5,1:2)');
    assignin('base',strcat(labels{1,1},'_unw_1970s_se') ,data(6,1:2)');

    assignin('base',strcat(labels{1,1},'_unw_2000s_est'),data(9 ,1:2)');
    assignin('base',strcat(labels{1,1},'_unw_2000s_se') ,data(10,1:2)');
for i=3:2:N-5
    assignin('base',strcat(labels{1,i},'_est'),data(1,i:i+1)');
    assignin('base',strcat(labels{1,i},'_se') ,data(2,i:i+1)');

    assignin('base',strcat(labels{1,i},'_1970s_est'),data(5,i:i+1)');
    assignin('base',strcat(labels{1,i},'_1970s_se') ,data(6,i:i+1)');

    assignin('base',strcat(labels{1,i},'_2000s_est'),data(9 ,i:i+1)');
    assignin('base',strcat(labels{1,i},'_2000s_se') ,data(10,i:i+1)');
end
    assignin('base',strcat(labels{1,13},'_est'),data(1,13:14)');
    assignin('base',strcat(labels{1,13},'_se') ,data(2,13:14)');
    assignin('base',strcat(labels{1,15},'_MPS_est'),data(1,15:16)');
    assignin('base',strcat(labels{1,15},'_MPS_se') ,data(2,15:16)');

%% Plot Fig. IX(a): VShape of labor share of LL establishments
figure('position',[0 0 w h]);
hold on
a=bar([x_CMF x_CMF],[dLS_est dLS_unw_est],1);
errorbar([x_CMF-0.14 x_CMF+0.14],[dLS_est dLS_unw_est],se*[dLS_se dLS_unw_se],'.','linewidth',1,'color','k','marker','o','markerfacecolor','k')
a(1).FaceColor = col(2,:);
a(2).FaceColor = col(3,:);
ax = gca;ax.YGrid = 'on';
set(gca,'ylim',[-0.32 0.0],'ytick',(-0.3:0.05:0.0),'xtick',x_CMF,'ticklabelinterpreter','latex');
set(gca,'XTickLabel',{'$t-5\;$ to $\;t$' '$t-5\;$ to $\;t+5$'},'fontsize',fntsize)
xlabel('Cumulative change from ...','interpreter','latex','fontsize',fntsize)
title('$\Delta\lambda_t^{LL}-\Delta\lambda_t^{Non-LL}$: CMF','fontsize',fntsize,'interpreter','latex');
lgnd=legend([a(1) a(2)],{'VA-weighted';'Unweighted'},'fontsize',fntsize,'location','se','interpreter','latex');
set(lgnd,'color','white');
if printyes==1
    print('../Figures/Fig_VShape_LS_cum.eps','-depsc')
end

%% Plot Fig. X: VShape of components of labor share of LL establishments
[bar_pos,bar_neg,x_pos,x_neg]=barstacked([d_log_W_est d_log_L_est -d_log_VA_est]);
figure('position',[0 0 w h]);
b1  =bar((0:1)'*ones(1,3),bar_pos,0.5,'stacked');
hold on
b2  =bar((0:1)'*ones(1,3),bar_neg,0.5,'stacked');
errorbar([0 -0.1 0.1;1 0.9 1.1],x_pos,se*[d_log_W_se d_log_L_se d_log_VA_se],'.','linewidth',1,'color','k','marker','o','markerfacecolor','k')
errorbar([0 -0.1 0.1;1 0.9 1.1],x_neg,se*[d_log_W_se d_log_L_se d_log_VA_se],'.','linewidth',1,'color','k','marker','o','markerfacecolor','k')
b1(1).FaceColor = col(4,:);
b1(2).FaceColor = col(3,:);
b1(3).FaceColor = col(2,:);
b2(1).FaceColor = col(4,:);
b2(2).FaceColor = col(3,:);
b2(3).FaceColor = col(2,:);
set(gca,'ylim',[-0.56 0.15],'ytick',(-0.5:0.1:0.1),'xlim',[-0.5 1.5],'xtick',x_CMF,'ticklabelinterpreter','latex','XTickLabel',{'$t-5\;$ to $\;t$' '$t-5\;$ to $\;t+5$'},'fontsize',fntsize)
ax = gca;
ax.YGrid = 'on';
xlabel('Cumulative change from ...','interpreter','latex','fontsize',fntsize)
title('Growth rate of components of $\Delta\log\lambda^{LL}$','fontsize',fntsize,'interpreter','latex');
lgnd=legend([b1(2);b1(1);b1(3)],{'Labor $\Delta\log L^{LL}$';'Wages $\Delta\log W^{LL}$';'Value added $\Delta\log Y^{LL}$'},'fontsize',fntsize,'location','se','interpreter','latex');
set(lgnd,'color','white');
if printyes==1
    print('../Figures/Fig_VShape_WandVAandL_cum_NEW.eps','-depsc')
end

%% Plot Fig. XI: VShape of labor share of LL establishments 1970s and 2000s
figure('position',[0 0 w h]);
hold on
a=bar([x_CMF x_CMF],[dLS_1970s_est dLS_unw_1970s_est],1); 
errorbar([x_CMF-0.14 x_CMF+0.14],[dLS_1970s_est dLS_unw_1970s_est],se*[dLS_1970s_se dLS_unw_1970s_se],'.','linewidth',1,'color','k','marker','o','markerfacecolor','k')
a(1).FaceColor = col(2,:);
a(2).FaceColor = col(3,:);
ax = gca;ax.YGrid = 'on';
set(gca,'ylim',[-0.365 0.015],'ytick',(-0.35:0.05:0.0),'xtick',x_CMF,'ticklabelinterpreter','latex');
set(gca,'XTickLabel',{'$t-5\;$ to $\;t$' '$t-5\;$ to $\;t+5$'},'fontsize',fntsize)
xlabel('Cumulative change from ...','interpreter','latex','fontsize',fntsize)
title('$\Delta\lambda_t^{LL}-\Delta\lambda_t^{Non-LL}$: 1970s','fontsize',fntsize,'interpreter','latex');
lgnd=legend([a(1) a(2)],{'VA-weighted';'Unweighted'},'fontsize',fntsize,'location','se','interpreter','latex');
set(lgnd,'color','white');
if printyes==1
    print('../Figures/Fig_VShape_LS_cum1970s.eps','-depsc')
end

figure('position',[0 0 w h]);
hold on
a=bar([x_CMF x_CMF],[dLS_2000s_est dLS_unw_2000s_est],1); 
errorbar([x_CMF-0.14 x_CMF+0.14],[dLS_2000s_est dLS_unw_2000s_est],se*[dLS_2000s_se dLS_unw_2000s_se],'.','linewidth',1,'color','k','marker','o','markerfacecolor','k')
a(1).FaceColor = col(2,:);
a(2).FaceColor = col(3,:);
ax = gca;ax.YGrid = 'on';
set(gca,'ylim',[-0.365 0.015],'ytick',(-0.35:0.05:0.0),'xtick',x_CMF,'ticklabelinterpreter','latex');
set(gca,'XTickLabel',{'$t-5\;$ to $\;t$' '$t-5\;$ to $\;t+5$'},'fontsize',fntsize)
xlabel('Cumulative change from ...','interpreter','latex','fontsize',fntsize)
title('$\Delta\lambda_t^{LL}-\Delta\lambda_t^{Non-LL}$: 2000s','fontsize',fntsize,'interpreter','latex');
lgnd=legend([a(1) a(2)],{'VA-weighted';'Unweighted'},'fontsize',fntsize,'location','se','interpreter','latex');
set(lgnd,'color','white');
if printyes==1
    print('../Figures/Fig_VShape_LS_cum2000s.eps','-depsc')
end

%% Plot Fig. XIII: VShape of components of labor share of LL establishments 1970s and 2000s
[bar_pos,bar_neg,x_pos,x_neg]=barstacked([d_log_W_1970s_est d_log_L_1970s_est -d_log_VA_1970s_est]);
figure('position',[0 0 w h]);
b1  =bar((0:1)'*ones(1,3),bar_pos,0.4,'stacked');
hold on
b2  =bar((0:1)'*ones(1,3),bar_neg,0.4,'stacked');
errorbar([0 -0.1 0.1;1 0.9 1.1],x_pos,se*[d_log_W_1970s_se d_log_L_1970s_se d_log_VA_1970s_se],'.','linewidth',1,'color','k','marker','o','markerfacecolor','k')
errorbar([0 -0.1 0.1;1 0.9 1.1],x_neg,se*[d_log_W_1970s_se d_log_L_1970s_se d_log_VA_1970s_se],'.','linewidth',1,'color','k','marker','o','markerfacecolor','k')
b1(1).FaceColor = col(4,:);
b1(2).FaceColor = col(3,:);
b1(3).FaceColor = col(2,:);
b2(1).FaceColor = col(4,:);
b2(2).FaceColor = col(3,:);
b2(3).FaceColor = col(2,:);
set(gca,'xlim',[-0.5 1.5],'ylim',[-0.77 0.26],'ytick',(-0.75:0.15:0.15),'xtick',x_CMF,'ticklabelinterpreter','latex','XTickLabel',{'$t-5\;$ to $\;t$' '$t-5\;$ to $\;t+5$'},'fontsize',fntsize)
ax = gca;
ax.YGrid = 'on';
xlabel('Cumulative change from ...','interpreter','latex','fontsize',fntsize)
title('Growth rate of components of $\Delta\log\lambda^{LL}$: 1970s','fontsize',fntsize,'interpreter','latex');
lgnd=legend([b1(2);b1(1);b1(3)],{'Labor $\Delta\log L^{LL}$';'Wages $\Delta\log W^{LL}$';'Value added $\Delta\log Y^{LL}$'},'fontsize',fntsize,'location','se','interpreter','latex');
set(lgnd,'color','white');
if printyes==1
    print('../Figures/Fig_VShape_WandVAandL1970_cumGR.eps','-depsc')
end

% Wages versus VA versus L - 2000
[bar_pos,bar_neg,x_pos,x_neg]=barstacked([d_log_W_2000s_est d_log_L_2000s_est -d_log_VA_2000s_est]);
figure('position',[0 0 w h]);
b1  =bar((0:1)'*ones(1,3),bar_pos,0.4,'stacked');
hold on
b2  =bar((0:1)'*ones(1,3),bar_neg,0.4,'stacked');
errorbar([0 -0.1 0.1;1 0.9 1.1],x_pos,se*[d_log_W_2000s_se d_log_L_2000s_se d_log_VA_2000s_se],'.','linewidth',1,'color','k','marker','o','markerfacecolor','k')
errorbar([0 -0.1 0.1;1 0.9 1.1],x_neg,se*[d_log_W_2000s_se d_log_L_2000s_se d_log_VA_2000s_se],'.','linewidth',1,'color','k','marker','o','markerfacecolor','k')
b1(1).FaceColor = col(4,:);
b1(2).FaceColor = col(3,:);
b1(3).FaceColor = col(2,:);
b2(1).FaceColor = col(4,:);
b2(2).FaceColor = col(3,:);
b2(3).FaceColor = col(2,:);
set(gca,'xlim',[-0.5 1.5],'ylim',[-0.77 0.25],'ytick',(-0.75:0.15:0.15),'xtick',x_CMF,'ticklabelinterpreter','latex','XTickLabel',{'$t-5\;$ to $\;t$' '$t-5\;$ to $\;t+5$'},'fontsize',fntsize)
ax = gca;
ax.YGrid = 'on';
xlabel('Cumulative change from ...','interpreter','latex','fontsize',fntsize)
title('Growth rate of components of $\Delta\log\lambda^{LL}$: 2000s','fontsize',fntsize,'interpreter','latex');
lgnd=legend([b1(2);b1(1);b1(3)],{'Labor $\Delta\log L^{LL}$';'Wages $\Delta\log W^{LL}$';'Value added $\Delta\log Y^{LL}$'},'fontsize',fntsize,'location','se','interpreter','latex');
set(lgnd,'color','white');
if printyes==1
    print('../Figures/Fig_VShape_WandVAandL2000_cumGR.eps','-depsc')
end

%% Fig. B.3 Comparison Full Sample and Matched Price Sample
figure('position',[0 0 w h]);
hold on
a=bar([x_CMF x_CMF],[d_log_Sales_est d_log_Sales_MPS_est],1);
errorbar([x_CMF-0.14 x_CMF+0.14],[d_log_Sales_est d_log_Sales_MPS_est]-0.001,se*[d_log_Sales_se d_log_Sales_MPS_se],'.','linewidth',1,'color','k','marker','o','markerfacecolor','k')
a(1).FaceColor = col(2,:);
a(2).FaceColor = col(3,:);
ax = gca;ax.YGrid = 'on';
set(gca,'ylim',[-0.05 0.25],'ytick',(-0.05:0.05:0.25),'xtick',x_CMF,'ticklabelinterpreter','latex');
set(gca,'XTickLabel',{'$t-5\;$ to $\;t$' '$t-5\;$ to $\;t+5$'},'fontsize',fntsize)
xlabel('Cumulative change from ...','interpreter','latex','fontsize',fntsize)
title('Growth of sales/worker $\Delta(pq/l)$ of $LL$ establishments','interpreter','latex','fontsize',fntsize);
lgnd=legend(a,{'Full Census Sample';'Matched Price Sample'},'fontsize',fntsize,'location','ne','interpreter','latex');
set(lgnd,'color','white');
if printyes==1
    print('../Figures/Fig_VShape_TVS_L_cum.eps','-depsc')
end


















